package day10.problem2;

//买卖股票的最好时机1
//https://www.nowcoder.com/practice/351b87e53d0d44928f4de9b6217d36bb?tpId=230&tqId=39767&ru=/exam/oj

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        int ret = 0;
        int m = in.nextInt();
        for(int i = 1; i<n; i++) {
            int x = in.nextInt();
            ret = Math.max(ret, x-m);
            m = Math.min(m, x);
        }
        System.out.println(ret);
    }
}